function e(e, t, a) {
    return t in e ? Object.defineProperty(e, t, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = a, e;
}

var t, a = require("../../utils/function.js"), n = require("../../api.js"), o = require("../../utils/qqmap-wx.js"), s = getApp(), r = wx.getStorageSync("MAP_KEY") || "PNIBZ-QF5R2-XSGUL-CGVXI-5J4GZ-VNFNX", i = new o({
    key: r
});

Component({
    properties: {
        paramA: Number,
        paramB: String
    },
    data: {
        home_show_class: "home_container_right",
        img: a.userImg,
        markers: {},
        polyline: [ {
            points: [],
            color: "#0299de",
            width: 9,
            dottedLine: !1,
            arrowLine: !0
        } ],
        controls: [ {
            id: 1,
            iconPath: "/images/user/icon-22.png",
            position: {
                left: 10,
                top: 10,
                width: 50,
                height: 50
            },
            clickable: !0
        } ],
        drivers: [ {
            id: "001",
            title: "1名司机"
        }, {
            id: "002",
            title: "2名司机"
        }, {
            id: "003",
            title: "3名司机"
        }, {
            id: "004",
            title: "4名司机"
        }, {
            id: "005",
            title: "5名司机"
        }, {
            id: "006",
            title: "6名司机"
        }, {
            id: "007",
            title: "7名司机"
        }, {
            id: "008",
            title: "8名司机"
        } ],
        startAddress: null,
        endAddress: null,
        longitude: null,
        latitude: null,
        orderOrMore: !0,
        driverCount: -1,
        pageRight: 0,
        myShow: !0,
        zuoyou: "icon-zuoyou",
        avatar: "/images/user/icon-07.png",
        buttonText: "登录",
        username: "未登录",
        orderGoing: !1,
        showTimeContainer: !1,
        date: [ "今天", "明天", "后天" ],
        hours: [],
        minute: [],
        homeHandlerShow: !0,
        about_time: [],
        phone: "",
        make: {},
        Hmap: "",
        left_width: 750,
        is_distance: !1
    },
    methods: (t = {
        onLoad: function() {
            var e = this;
            wx.getSystemInfo({
                success: function(t) {
                    var a = t.screenWidth / 375, n = t.screenHeight;
                    console.log("屏幕screenHeight--\x3e" + n), wx.createSelectorQuery().select(".right_page").boundingClientRect(function(t) {
                        var n = t.height;
                        console.log("可见height--\x3e" + n);
                        var o = 500 * a / 2;
                        e.setData({
                            map_height: 2 * (n - o)
                        });
                    }).exec();
                }
            });
        },
        show_left_page: function() {
            "home_container_right" == this.data.home_show_class ? this.setData({
                home_show_class: "home_container_left"
            }) : this.setData({
                home_show_class: "home_container_right"
            });
        }
    }, e(t, "onLoad", function(e) {
        this.setData({
            startAddress: wx.getStorageSync("startAddress"),
            phone: wx.getStorageSync("userPhone")
        }), "" !== wx.getStorageSync("endAddress") && this.setData({
            endAddress: wx.getStorageSync("endAddress")
        }), "" !== wx.getStorageSync("phonep") && (this.setData({
            avatar: wx.getStorageSync("userMessage").avatar,
            username: wx.getStorageSync("userMessage").username,
            buttonText: wx.getStorageSync("userMessage").buttonText,
            phone: wx.getStorageSync("phonep")
        }), s.request({
            url: n.order.for_order,
            method: "post",
            data: {},
            success: function(e) {
                1 == e.code ? 1 == e.data.utype ? wx.reLaunch({
                    url: "../../index/index"
                }) : 0 == e.data.is_send ? a.intoPageHandler("../orderAndDriverGoing/orderAndDriverGoing?order_no=" + e.data.order_no) : 1 == e.data.is_send && 0 == e.data.initiate && 0 == e.data.is_service ? a.intoPageHandler("../getOrderNotGoing/getOrderNotGoing?order_no=" + e.data.order_no) : 1 == e.data.is_send && 0 == e.data.initiate ? a.intoPageHandler("../orderGoing/orderGoing?order_no=" + e.data.order_no) : 1 == e.data.initiate && a.intoPageHandler("../../pay/paidOrder/paidOrder?order_no=" + e.data.order_no) : 1 == e.data.utype && wx.reLaunch({
                    url: "../../index/index"
                });
            }
        })), this.changeIcon();
    }), e(t, "regionchange", function(e) {
        console.log("regionchange", e.type);
    }), e(t, "markertap", function(e) {
        console.log("markertap", e.markerId);
    }), e(t, "controltap", function(e) {
        var t = this;
        if (console.log("map controltap", e.controlId), this.show_left_page(), 1 === e.controlId) this.openMyPageHandler(); else a.getLatLntHandler(function(e) {
            t.setData({
                startAddress: e.startAddress
            });
        });
    }), e(t, "openMyPageHandler", function() {
        var e = this.data, t = (e.pageRight, e.myShow);
        t ? this.setData({
            pageRight: 620,
            left_width: 130,
            myShow: !t,
            controls: [ {
                id: 1,
                iconPath: "/images/user/icon-33.png",
                position: {
                    top: 144,
                    left: 10,
                    width: 41,
                    height: 41
                },
                clickable: !0
            } ],
            homeHandlerShow: !1
        }) : (this.setData({
            pageRight: 0,
            left_width: 750,
            myShow: !t,
            controls: [ {
                id: 1,
                iconPath: "/images/user/icon-22.png",
                position: {
                    left: 10,
                    top: 10,
                    width: 50,
                    height: 50
                },
                clickable: !0
            }, {
                id: 2,
                iconPath: "/images/user/icon-30.png",
                position: {
                    top: 240,
                    left: 10,
                    width: 50,
                    height: 50
                },
                clickable: !0
            } ],
            homeHandlerShow: !0
        }), this.changeIcon());
    }), e(t, "callPhoneHandler", function() {
        a.intoPageHandler("../../order/helpFriendDownloadOrder/helpFriendDownloadOrder");
    }), e(t, "getMoreDriverHandler", function() {
        this.setData({
            orderOrMore: !this.data.orderOrMore
        });
    }), e(t, "bindChange", function(e) {
        console.log("司机数量", e.detail.value[0]), this.setData({
            driverCount: e.detail.value[0] + 1
        }), console.log(this.data.driverCount);
    }), e(t, "getDriverCountHandler", function() {
        this.setData({
            orderOrMore: !this.data.orderOrMore
        });
    }), e(t, "callServerHandler", function() {
        if ("登录" === this.data.buttonText) a.showToast("请先登录", "none"), this.openMyPageHandler(); else if (null === this.data.endAddress) a.showToast("请输入目的地", "none"); else {
            var e = "" === wx.getStorageSync("relative_people") ? wx.getStorageSync("user") : wx.getStorageSync("relative_people");
            s.request({
                url: n.order.place_order,
                method: "post",
                data: {
                    startAddress: JSON.stringify(this.data.startAddress),
                    endAddress: JSON.stringify(this.data.endAddress),
                    driver_count: -1 === this.data.driverCount ? 1 : this.data.driverCount,
                    passenger_phone: e.phone,
                    passenger_name: e.name,
                    paid: e.replace_pay,
                    type: e.type,
                    about_time: this.data.about_time,
                    hours: this.data.hours,
                    minute: this.data.minute,
                    dat: this.data.date,
                    travel_type : o.travel_type
                },
                success: function(e) {
                    console.log("下单成功", e), 1 == e.code && e.data.orderid ? (wx.setStorageSync("orderid", e.data.orderid), 
                    wx.navigateTo({
                        url: "../orderAndDriverGoing/orderAndDriverGoing?order_no=" + e.data.orderid
                    })) : a.showToast(e.msg, "none");
                }
            });
        }
    }), e(t, "orderGoingHandler", function() {
        a.showToast("您还没有进行中的订单", "none");
    }), e(t, "onShow", function() {
        var e = this;
        wx.setStorageSync("serverphone", "029-86263319"), setInterval(function() {
            var t = [];
            if (t = wx.getStorageSync("positioning"), console.log("获取代驾列表", t), t) {
                e.setData({
                    startAddress: wx.getStorageSync("startAddress")
                });
                var a = [];
                if ("" !== wx.getStorageSync("endAddress") && "" !== wx.getStorageSync("startAddress")) {
                    var n = wx.getStorageSync("startAddress"), o = wx.getStorageSync("endAddress");
                    a[a.length] = {
                        id: a.length,
                        iconPath: "/images/user/icon-44.png",
                        latitude: n.location.lat,
                        longitude: n.location.lng,
                        width: 40,
                        height: 40
                    }, a[a.length] = {
                        id: a.length,
                        iconPath: "/images/user/icon-43.png",
                        latitude: o.location.lat,
                        longitude: o.location.lng,
                        width: 40,
                        height: 40
                    }, a.push(t.positino), e.setData({
                        make: a,
                        startAddress: wx.getStorageSync("startAddress")
                    });
                } else e.setData({
                    make: t.positino
                });
            } else e.setData({
                startAddress: wx.getStorageSync("startAddress")
            });
        }, 5e3), "" !== wx.getStorageSync("endAddress") && "" !== wx.getStorageSync("startAddress") && (this.getPolyline(wx.getStorageSync("startAddress"), wx.getStorageSync("endAddress")), 
        this.get_distance(wx.getStorageSync("startAddress"), wx.getStorageSync("endAddress"), function(t) {
            e.setData({
                distance: (t.distance.elements[0].distance / 1e3).toFixed(3),
                is_distance: !0
            });
        }), s.request({
            url: n.order.geticon,
            method: "post",
            data: {
                start: wx.getStorageSync("startAddress").location,
                end: wx.getStorageSync("endAddress").location
            },
            success: function(e) {
                console.log(e, "222222");
            }
        }));
    }), e(t, "getPolyline", function(e, t) {
        var a = this, n = this.data.polyline, o = e.location.lat + "," + e.location.lng + "&to=" + t.location.lat + "," + t.location.lng ,p = '&policy=LEAST_DISTANCE';
        wx.request({
            url: "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + o + "&key=" + r + p,
            header: {
                "content-type": "application/json"
            },
            success: function(e) {
                if (384 === e.data.status) ; else {
                    for (var t = e.data.result.routes[0].polyline, o = 2; o < t.length; o++) t[o] = t[o - 2] + t[o] / 1e6;
                    for (var s = [], r = 0; r < t.length; r += 2) s[s.length] = {
                        longitude: t[r + 1],
                        latitude: t[r]
                    };
                    console.log(s), n[0].points = s, console.log(n), a.setData({
                        polyline: n
                    });
                }
            },
            fail: function() {}
        });
    }), e(t, "get_distance", function(e, t, a) {
        i.calculateDistance({
            from: {
                latitude: e.location.lat,
                longitude: e.location.lng
            },
            to: [ {
                latitude: t.location.lat,
                longitude: t.location.lng
            } ],
            success: function(e) {
                console.log(e.result.elements[0].distance), a({
                    distance: e.result
                });
            },
            fail: function(e) {
                a(e);
            },
            complete: function(e) {
                console.log(e);
            }
        });
    }), e(t, "loginHandler", function(e) {
        var t = this;
        "登录" === this.data.buttonText ? a.loginHandler(function(e) {
            console.log("用户信息事件", wx.getStorageSync("userMessage")), t.getUserInfo();
        }) : (console.log("退出登录"), s.request({
            url: n.user.loginout,
            method: "post",
            data: {},
            success: function(e) {
                1 == e.code && (wx.removeStorageSync("userMessage"), wx.removeStorageSync("phonep"), 
                wx.removeStorageSync("access_token"), wx.removeStorage({
                    key: "access_token"
                })), wx.showToast({
                    title: e.msg,
                    duration: 2e3
                });
            }
        }), this.setData({
            avatar: "/images/user/icon-07.png",
            username: "未登录",
            buttonText: "登录",
            phone: ""
        }));
    }), e(t, "getUserInfo", function(e) {
        a.showModal("获取手机号码", "我们需要获取你的电话号码，一边与和你保持实时的联系，防止你的订单丢失", function(e) {
            e && wx.getUserProfile({
                success: function(e) {
                    wx.login({
                        success: function(t) {
                            s.request({
                                url: n.user.login,
                                method: "post",
                                data: {
                                    code: t.code,
                                    iv: e.iv,
                                    encryptedData: e.encryptedData
                                },
                                success: function(e) {
                                    1 == e.code ? (wx.setStorageSync("access_token", e.data.access_token), wx.setStorageSync("phonep", e.data.phone), 
                                    wx.setStorageSync("utype", e.data.type), wx.setStorageSync("price", e.data.price), 
                                    1 == e.data.type ? wx.reLaunch({
                                        url: "../../index/index"
                                    }) : 1 == e.data.is_binding ? wx.reLaunch({
                                        url: "./driverServer"
                                    }) : wx.reLaunch({
                                        url: "../../user/getPhone/getPhone"
                                    }), wx.setStorageSync("is_binding", e.data.is_binding)) : wx.removeStorage({
                                        key: "access_token"
                                    });
                                }
                            });
                        }
                    });
                }
            });
        });
    }), e(t, "intoPageHandler", function(e) {
        a.intoPageHandler(e.currentTarget.dataset.skip);
    }), e(t, "startAddress", function() {
        wx.chooseLocation({
            success: function(e) {
                console.log(e), wx.setStorageSync("startAddress", {
                    title: e.name,
                    address: e.address,
                    location: {
                        lat: e.latitude,
                        lng: e.longitude
                    }
                });
            }
        });
    }), e(t, "endAddress", function() {
        var e = this;
        wx.chooseLocation({
            success: function(t) {
                e.setData({
                    endAddress: {
                        title: t.name,
                        address: t.address,
                        location: {
                            lat: t.latitude,
                            lng: t.longitude
                        }
                    }
                }), wx.setStorageSync("endAddress", {
                    title: t.name,
                    address: t.address,
                    location: {
                        lat: t.latitude,
                        lng: t.longitude
                    }
                });
            }
        });
    }), e(t, "relstiveServerHandler", function() {
        a.callPhoneHandler(wx.getStorageSync("serverphone"));
    }), e(t, "selectTimeShowTimeHandler", function() {
        this.setData({
            showTimeContainer: !0,
            homeHandlerShow: !1
        }), this.selectTimeHandler(0, 0, 0);
    }), e(t, "getTimeHandlerCancle", function() {
        this.setData({
            showTimeContainer: !1,
            homeHandlerShow: !0
        });
    }), e(t, "getTimeHandlerOk", function() {
        var e = this.data, t = e.hours, a = e.minute;
        console.log(t, a, "1111111111111111111"), this.setData({
            showTimeContainer: !1,
            homeHandlerShow: !0
        });
    }), e(t, "bindTimeChange", function(e) {
        console.log("预约时间", e.detail.value), this.setData({
            about_time: e.detail.value
        }), 0 === e.detail.value[0] && 0 === e.detail.value[1] ? this.selectTimeHandler(0, 0) : 0 === e.detail.value[0] && 0 !== e.detail.value[1] ? this.selectTimeHandler(0, e.detail.value[1]) : 0 !== e.detail.value[0] && this.selectTimeHandler(e.detail.value[0], e.detail.value[1], 0);
    }), e(t, "selectTimeHandler", function(e, t, a) {
        var n = this.data, o = n.hours, s = n.minute, r = new Date().getHours();
        if (o.length = 0, s.length = 0, console.log(e, t, a), 0 === e && 0 === t) {
            o.push("现在");
            for (i = r + 1; i < 24; i++) o.push(i + "点");
            this.setData({
                hours: o,
                minute: s
            });
        } else if (0 === e && 0 !== t) {
            o.push("现在");
            for (i = r + 1; i < 24; i++) o.push(i + "点");
            for (i = 0; i < 60; i += 10) s.push(i);
            this.setData({
                hours: o,
                minute: s
            });
        } else if (0 !== e) {
            for (i = 0; i < 24; i++) o.push(i + "点");
            for (var i = 0; i < 60; i += 10) s.push(i);
            this.setData({
                hours: o,
                minute: s
            });
        }
    }), e(t, "changeIcon", function() {
        var e = this, t = this.data.controls;
        wx.getSystemInfo({
            success: function(a) {
                var n = a.windowWidth / 750 * 500, o = a.windowHeight - n;
                t[1] = {
                    id: 2,
                    iconPath: "/images/user/icon-30.png",
                    position: {
                        top: o - 56,
                        left: 10,
                        width: 50,
                        height: 50
                    },
                    clickable: !0
                }, e.setData({
                    winPath: {
                        w: a.windowWidth,
                        h: a.windowHeight
                    },
                    map_height: o,
                    controls: t
                });
            }
        });
    }), t),
    onShareAppMessage: function() {
        return {
            title: s.shareAppMessage().title,
            imageUrl: s.shareAppMessage().imageUrl,
            desc: s.shareAppMessage().desc,
            path: s.shareAppMessage().path
        };
    }
});